░░▓██                                                                        
           ▒▓███                                                                        
          ░▒▓█▓█                                                                        
         ░▒▓█▓▓█                                                                        
        ░░▓▓█▒▒▓█                                                        ░█             
        ░▒▓█░▒▒▓█                                                       ░▒█             
       ░▒▓██ ░▒▓██                                                      ░▒█ ░▒████████  
      ░▒▓██   ░▒▓█        ████████      ░████       ████      ▒██      ░▒▒█░▒▒█▒▒▒▒▒▒█  
     ░▒▒▓█     ░▓█ ████████▓█████    ░▒███▒▒█     ░██▒▒██    ░▒██      ░▒██░▒▒█░░░░ ██  
     ░▒▓██   ███████▓▓▓▓▓▒▒██▒▒▒█  ░░▒██▒▒░▒█   ░▒█▒▒▒░▒██   ░▒███     ░▒█ ░▒██         
     ░▒▓██████▓▓▒▓█▒▒▒ ░▒▒█░░░░    ░░▒█ ░░░    ░▒█░░░  ░▒█  ░▒██▒██   ░▒▒█ ░▒█          
     █████▓▓▓▒▒ ▒▓█     ░▒▒█       ░▒██       ░▒██     ░▒█  ░▒█▒▒▒█   ░▒█  ░▒█   ░▒█    
  ██████▓▒▓      ▒▓█     ░░▒██     ░▒█        ░▒█      ░▒█ ░▒██░░▒▒█ ░▒▒█  ▒▒███████    
 ██▓▓▓█ ▒        ▒▓█      ░▒▒▒███  ░▒█        ░▒█     ░▒██ ░▒█  ░░▒██░▒██ ░▒▒█▒▒▒▒██    
▒▓▒▒▓██          ▒▒▓█   ░█  ░▒▒▒██ ░▒█        ░▒█    ░░▒█ ░▒██    ░▒█░▒█  ░▒▒█░░░░▒     
░░▒▓██            ▒▓█  ░▒█    ░▒▒█ ░▒█    ░▒█ ░▒█    ░░██ ░▒█     ░▒████ ░░▒██          
 ░▒▓█▒            ▒▓█  ░▒█    ████ ░▒███ ░▒██ ░▒███ ░░██  ▒██      ░▒██  ░▒▒█      ▒█   
 ░▒██             ▒▒▓█  ░▒█████▒▒   ░▒▒▒███▒▒ ░▒▒▒████▒▒ ░▒██       ▒█  ░░▒▒██████░▒█   
░▒▓█▒             ▒▒▓█   ░▒▒▒▒▒      ░░▒░░▒░░  ░░░▒▒▒▒░  ░▒█         ▒    ░░▒▒▒▒▒▒███       /\_      
░▓██               ▒▒▓   ░░░░          ░░░       ░░░░░   ░▒█                 ░░░▒▒▒▒▒▒    (゚、 。`7 
░▒▒                  ▒                                  ░▒██                    ░░░░░░░    {`  ~ \   )
 ░                                                       ░▒▒                                ),),\_,)/

Getting Shader Property After Animation.md

Creative/VRChat/Getting Shader Property After Animation.md
  • date:
  • tags: ['unity']
  • meow: yes

Writing this here because this gave me and some friends a headache.

In Unity, animation that change materials do not actually modify the material itself. Instead they animate a MaterialPropertyBlock.

To get the color after animating, you can use the following snippet:

MaterialPropertyBlock properties = new MaterialPropertyBlock();
renderer.GetPropertyBlock(properties);
Vector4 color = properties.GetVector("_Color");
Debug.Log("color: " + color);

You probably want to run this in the late update, since that runs after animations.

I found the original solution here: https://discussions.unity.com/t/after-animating-a-custom-material-shader-parameter-how-do-i-get-an-accurate-value-from-script/134688